/**
 * 
 */
package com.unsanctioned.radioagregator.database;


import org.json.JSONObject;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * @author wizard
 *
 */
public class DBCouncelor extends SQLiteOpenHelper {
	private static String DB_NAME = "AppDB";
	private static int DB_VERSION = 1;
	private static DBCouncelor instance;
	
	public static String CREATE_PLAYLIST_INDEX = ""
		+ "IF NOT EXISTS "
		+ "CREATE TABLE playlist("
		+ "	no INTEGER, name TEXT, "
		+ " 	PRIMARY KEY(no ASC)"
		+ ")";
	public static String CREATE_GENERAL_TABLE = ""
		+ "IF NOT EXISTS "
		+ "CREATE TABLE general("
		+ "	no				INTEGER,"
		+ "	radio_id		INTEGER,"
		+ "	radio_name		TEXT,"
		+ "	content_id		INTEGER,"
		+ "	content_name	TEXT,"
		+ "	content_data	TEXT,"
		+ "	content_picture	TEXT,"
		+ "	last_accessed	DATE,"
		+ "	owner			TEXT,"
		+ "	favorite		BOOLEAN,"
		+ "		PRIMARY KEY(no ASC)"
		+ ")";
	public static String ID = "id";
	public static String NAME = "name";
	public static String OWNER = "owner";
	/**
	 * Default constructor.
	 * @param context
	 */
	public DBCouncelor(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
		instance = this;
	}
	/**
	 * Original constructor, if you want to define database on your own.
	 * @param context - <i>see original class</i>.
	 * @param name - <i>see original class</i>.
	 * @param factory - <i>see original class</i>.
	 * @param version - <i>see original class</i>.
	 */
	public DBCouncelor(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}
	public static DBCouncelor getInstance(Context context) {
		if (instance == null) return new DBCouncelor(context);
		else return instance;
	}	
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		this.getWritableDatabase().execSQL(CREATE_PLAYLIST_INDEX);
		this.getWritableDatabase().execSQL(CREATE_GENERAL_TABLE);
	}
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		++DB_VERSION;
	}
	/**
	 * Retrieve all old data from database for show when application starts: advs, agenda, podcast, and club.
	 * @return a JSONObject instance containing those things. 
	 */
	public JSONObject getLastlySavedData() {
		return null;
	}
}
